package com.newtype.meeting.shared.tools;

import com.extjs.gxt.ui.client.binding.Converter;
import com.extjs.gxt.ui.client.widget.form.Field;
import com.extjs.gxt.ui.client.widget.form.Radio;
import com.extjs.gxt.ui.client.widget.form.RadioGroup;

public class RadioGroupConverter extends Converter {
	RadioGroup group;

	public RadioGroupConverter(RadioGroup group) {
		this.group = group;
	}

	@Override
	public Object convertFieldValue(Object value) {
		return ((Radio) value).getValueAttribute();
	}

	@Override
	public Object convertModelValue(Object value) {
		for (Field<?> rad : group.getAll())
			if (((Radio) rad).getValueAttribute() == value)
				return rad;
		return null;
	}
}
